<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        var arr1 = [1, 2, 3, 6, 4, 5, 3];
        //删除所有3
        for (var i in arr1) { // i是索引
            if (arr1[i] === 3) {
                arr1.splice(i, 1)
            }
        }
        console.log(arr1);

        var arr2 = [1, 2, 3, 3, 3, 3, 6, 4, 5];
        //删除所有的3 

        // for(var i in arr2){ // i是索引
        //     if(arr2[i] === 3){
        //         arr2.splice(i,1)
        //     }
        // }
        // console.log(arr2);
        // // splice(开始的索引,多少个)

        // 解决数组塌陷 

        for (var i = arr2.length - 1; i >= 0; i--) {
            if (arr2[i] === 3) {
                arr2.splice(i, 1)
            }
        }
        console.log(arr2);

        // 1.从右往左 删除可以解决数组塌陷的问题  

        

    </script>
</body>

</html>